package cn.wolfcode.mongodemo2.service.impl;

import cn.wolfcode.mongodemo2.domain.User;
import cn.wolfcode.mongodemo2.reporitory.UserReporitory;
import cn.wolfcode.mongodemo2.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserReporitory userReporitory;
    @Override
    public void save(User user) {
        userReporitory.save(user);
    }

    @Override
    public void delete(String id) {
        userReporitory.deleteById(id);
    }

    @Override
    public void update(User user) {
        userReporitory.save(user);
    }

    @Override
    public User get(String id) {
        Optional<User> byId = userReporitory.findById(id);
        return byId.orElse(null);
    }

    @Override
    public List<User> list() {
        return userReporitory.findAll();
    }

    @Override
    public User queryByName(String name) {
        User user = userReporitory.queryByName(name);
        return user;
    }
}
